package com.ruoyi.web.controller.tool;

import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.sign.Md5Utils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
@RequestMapping("/tool/md5")
public class MD5UtilController {

    @PostMapping("/encryption")
    public AjaxResult encryption(String data) {
        Optional.ofNullable(data).orElseThrow(() -> new ServiceException("请输入加密数据", HttpStatus.FORBIDDEN));
        return AjaxResult.success("操作成功", Md5Utils.hash(data));
    }
}
